--- title: "L1-016 查验身份证" created: 2025-11-28 tags: - 算法 --- # L1-016 查验身份证 ## 题目 [L1-016 查验身份证](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=994805122985476096&page=0) ![[image-70d0f55c.png]] ## 思路分析 isalpha/isdigit 字母/数字 ```cpp char c; //判断是否为字母: //可以这样: if(c>='a' && c<='z' || c>='A' && c<='Z') //也可用库函数: //检查一个字符是否是字母(a-z 或 A-Z)是 返回非零值,不是 返回零 if(isalpha(ch1)) //判断是否为数字: //可以这样: if(c>='0' && c<='9') //也可用库函数: //检查一个字符是否是十进制数字(0-9),是 返回非零值,不是 返回零 if(isdigit(int ch)) ``` ## 代码实现 ```cpp #include using namespace std; #define endl '\n' typedef long long LL; const int N=20; int q[N]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; char hs[N]={'1','0','X','9','8','7','6','5','4','3','2'}; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); // for(int i=0;i<17;i++) cout<>n; bool havefalse=false; while(n--){ string s;cin>>s; LL total=0; char jym=s.back(); bool isValid = true; for(int i=0;i<17;i++){ // if(isalpha(s[i])){ if(!isdigit(s[i])) { cout<